package pt.ipbeja.estig.eda;

public class InsertionSort
{
   int[] array;
   
   /**
    * Insertion Sort Construct
    * @param array Number list
    */
   public InsertionSort( int[] array )
   {
      this.array = array;
      //this.array = ( int[] )array.clone();
   }
   
   /**
    *Insertion Sort Method
    */
   public void sort()
   {
      for ( int j = 1; j < this.array.length; j++ )
      {
         int key = this.array[ j ];
         int i = j - 1;

         while( ( i > -1 ) && ( this.array[ i ] > key ) )
         {
            this.array[ i + 1 ] = this.array [ i ];
            i = i - 1;
         }
         
         this.array[ i + 1 ] = key;
      }
      
   }

}